#if !defined(QMITK_DataGeometry3DInteractor_H__INCLUDED)
#define QMITK_DataGeometry3DInteractor_H__INCLUDED

//#include "QmitkFunctionality.h"

#include <QmitkFunctionality.h>
#include <QmitkStandardViews.h>
#include <QmitkStdMultiWidgetEditor.h>

#include <mitkWeakPointer.h>

#include "ui_QmitkDataGeometry3DInteractorControls.h"

#include "WxPointedSticksInteractor.h"
#include "WxContourToolOverlay.h"
#include "WxObjectOrientationMarkerInteractor.h"

#include "mitkPlaneGeometry.h"
#include "mitkPlane.h"
#include "mitkExtractDirectedPlaneImageFilter.h"
#include "mitkWeakPointerProperty.h"




class QmitkStdMultiWidget;



/*!
\brief DataGeometry3DInteractor
Allows to measure distances, angles, etc.

\sa QmitkFunctionality
\ingroup org_mitk_gui_qt_DataGeometry3DInteractor_internal
*/
class QmitkDataGeometry3DInteractor : public QObject, public QmitkFunctionality
{
  Q_OBJECT
public :
    class QmitkExt_EXPORT ItkEventListener : public itk::Command
    {
    friend class QmitkDataGeometry3DInteractor;
    public:
        mitkClassMacro(ItkEventListener, itk::Command);
        ItkEventListener() : m_PlaneWidth(270),m_PlaneLength(240)
        {

        }
        virtual void 	Execute (itk::Object *  caller , const itk::EventObject & /* event */)
        {
          mitk::BaseData* data=dynamic_cast<mitk::BaseData*> (caller);
          if(data)
          {
          }
        };
        virtual void 	Execute (const itk::Object *  caller , const itk::EventObject & /* event */)
        {
            const mitk::BaseData* data=dynamic_cast<const mitk::BaseData*> (caller);
            if(data)
            {

                mitk::Geometry3D* g3d=data->GetGeometry();
                if(g3d==NULL) return;
                mitk::Point3D pos3d=g3d->GetOrigin();
                mitk::Vector3D planeVx=g3d->GetAxisVector(1)*(-1.0);  planeVx.Normalize();
                mitk::Vector3D planeVy=g3d->GetAxisVector(2)*(-1.0);  planeVy.Normalize();
                mitk::Vector3D planeVz=g3d->GetAxisVector(0);  planeVz.Normalize();
                pos3d=pos3d-planeVx*(m_PlaneWidth*0.5)-planeVy*m_PlaneLength;

                mitk::AffineTransform3D::Pointer affineTransform= mitk::AffineTransform3D::New();
                mitk::Vector3D pos;
                pos.Set_vnl_vector(pos3d.Get_vnl_vector());
                affineTransform->SetOffset(pos);
                mitk::AffineTransform3D::MatrixType m;
                m.GetVnlMatrix().set_column(0,planeVx.Get_vnl_vector());
                m.GetVnlMatrix().set_column(1,planeVy.Get_vnl_vector());
                m.GetVnlMatrix().set_column(2,planeVz.Get_vnl_vector());
                affineTransform->SetMatrix(m);
                affineTransform->Modified();
                m_Geometry3D->SetIndexToWorldTransform(affineTransform);
                m_Geometry3D->SetOrigin(pos3d);
                m_Geometry3D->Modified();
            }
        };
protected:
      float  m_PlaneWidth,m_PlaneLength;
      mitk::Geometry3D *m_Geometry3D;
    };

  public:
    QmitkDataGeometry3DInteractor();
    virtual ~QmitkDataGeometry3DInteractor();
    virtual void Activated();
    virtual void Deactivated();
    virtual bool IsExclusiveFunctionality() const;
    ///
    /// Called when the selection in the workbench changed
    ///
    virtual void OnSelectionChanged(std::vector<mitk::DataNode*> nodes);

    virtual void NodeRemoved(const mitk::DataNode* node);

  protected:
    // Pseudo Ctor
    void CreateQtPartControl(QWidget* parent);

  protected slots:

    void ControlData();
    void AddTestPlane();

  protected:
    /*!
    * controls containing sliders for scrolling through the slices
    */
    Ui::QmitkDataGeometry3DInteractorControls * m_Controls;
    bool m_IsControlling;
    /*
     * Interactor for performing the DataPositionings.
     */
    mitk::WeakPointer<mitk::WxObjectOrientationMarkerInteractor> m_ObjectOrientationMarkerInteractor;
    mitk::WeakPointer<mitk::DataNode> m_CtrlDataNode;

    long m_ObserverTag;
    ItkEventListener::Pointer m_ItkEventListener;
};

#endif // !defined(QMITK_DataGeometry3DInteractor_H__INCLUDED)

